package speedchina.vo.workhour;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import speedchina.exception.BaseException;

import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;


/**
 * @author earthchen
 * @date 2018/10/8
 **/
@ExcelTarget("workHourTableVO")
public class WorkHourTableVO implements Serializable
{

    public WorkHourTableVO()
    {
    }

    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @Excel(name = "项目编号")
    @NotEmpty(message = "项目编号必填")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long projectId;

    @NotEmpty(message = "项目类型必填")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long projectTypeId;

    @Excel(name = "项目名")
    private String projectName;

    @Excel(name = "项目类型")
    private String projectTypeName;

    @Excel(name = "用户id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;

    @Excel(name = "用户名")
    private String username;

    @Excel(name = "工作日期",exportFormat = "yyyy-MM-dd")
    @NotEmpty(message = "工作日期不能为空")
    @JsonFormat(pattern="yyyy-MM-dd")
    private Date workDate;

    @Excel(name = "工时",type = 10)
    @NotEmpty(message = "工时不能为空")
    private Float workHours;

    private String delFlag;

    @Excel(name = "任务信息")
    @NotEmpty(message = "任务信息不能为空")
    private String remark;

    private String mon;

    private String tues;

    private String wed;

    private String thur;

    private String fri;

    private String stat;

    private String sun;

    public String getUsername()
    {
        return username;
    }

    public void setUsername(String username)
    {
        this.username = username;
    }

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public Long getProjectId()
    {
        return projectId;
    }

    public void setProjectId(Long projectId)
    {
        this.projectId = projectId;
    }

    public Long getProjectTypeId()
    {
        return projectTypeId;
    }

    public void setProjectTypeId(Long projectTypeId)
    {
        this.projectTypeId = projectTypeId;
    }

    public Long getUserId()
    {
        return userId;
    }

    public void setUserId(Long userId)
    {
        this.userId = userId;
    }

    public Date getWorkDate()
    {
        return workDate;
    }

    /**
     * 设置工时日期和星期几
     *
     * @param workDate
     */
    public void setWorkDate(Date workDate)
    {
        this.workDate = workDate;

    }

    public String getProjectName()
    {
        return projectName;
    }

    public void setProjectName(String projectName)
    {
        this.projectName = projectName;
    }

    public String getProjectTypeName()
    {
        return projectTypeName;
    }

    public void setProjectTypeName(String projectTypeName)
    {
        this.projectTypeName = projectTypeName;
    }

    public Float getWorkHours()
    {
        return workHours;
    }

    public void setWorkHours(Float workHours)
    {
        this.workHours = workHours;
    }

    public String getDelFlag()
    {
        return delFlag;
    }

    public void setDelFlag(String delFlag)
    {
        this.delFlag = delFlag;
    }

    public String getRemark()
    {
        return remark;
    }

    public void setRemark(String remark)
    {
        this.remark = remark;
    }

    public String getMon()
    {
        return mon;
    }

    public void setMon(String mon)
    {
        this.mon = mon;
    }

    public String getTues()
    {
        return tues;
    }

    public void setTues(String tues)
    {
        this.tues = tues;
    }

    public String getWed()
    {
        return wed;
    }

    public void setWed(String wed)
    {
        this.wed = wed;
    }

    public String getThur()
    {
        return thur;
    }

    public void setThur(String thur)
    {
        this.thur = thur;
    }

    public String getFri()
    {
        return fri;
    }

    public void setFri(String fri)
    {
        this.fri = fri;
    }

    public String getStat()
    {
        return stat;
    }

    public void setStat(String stat)
    {
        this.stat = stat;
    }

    public String getSun()
    {
        return sun;
    }

    public void setSun(String sun)
    {
        this.sun = sun;
    }

    @Override
    public String toString()
    {
        return "WorkHourTableVO{" +
               "id=" + id +
               ", projectId=" + projectId +
               ", projectTypeId='" + projectTypeId + '\'' +
               ", userId=" + userId +
               ", username='" + username + '\'' +
               ", workDate=" + workDate +
               ", workHours=" + workHours +
               ", delFlag='" + delFlag + '\'' +
               ", remark='" + remark + '\'' +
               ", mon='" + mon + '\'' +
               ", tues='" + tues + '\'' +
               ", wed='" + wed + '\'' +
               ", thur='" + thur + '\'' +
               ", fri='" + fri + '\'' +
               ", stat='" + stat + '\'' +
               ", sun='" + sun + '\'' +
               '}';
    }

    public void setWeekHour()
    {
        Calendar cal = Calendar.getInstance();
        cal.setTime(this.workDate);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
        {
            w = 0;
        }
        switch (w)
        {
            case 0:
                setSun(getWorkHours().toString());
                break;
            case 1:
                setMon(getWorkHours().toString());
                break;
            case 2:
                setTues(getWorkHours().toString());
                break;
            case 3:
                setWed(getWorkHours().toString());
                break;
            case 4:
                setThur(getWorkHours().toString());
                break;
            case 5:
                setFri(getWorkHours().toString());
                break;
            case 6:
                setStat(getWorkHours().toString());
                break;
            default:
                break;
        }
    }

    /**
     * 将当前填写的周几的工时与日期对比，并赋值给工时
     */
    public void weekToDayHour()
        throws BaseException
    {
        setWorkHours(null);

        Calendar cal = Calendar.getInstance();
        cal.setTime(this.workDate);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
        {
            w = 0;
        }
        switch (w)
        {
            case 0:
                setWorkHours(Float.parseFloat(getSun()));
                break;
            case 1:
                setWorkHours(Float.parseFloat(getMon()));
                break;
            case 2:
                setWorkHours(Float.parseFloat(getTues()));
                break;
            case 3:
                setWorkHours(Float.parseFloat(getWed()));
                break;
            case 4:
                setWorkHours(Float.parseFloat(getThur()));
                break;
            case 5:
                setWorkHours(Float.parseFloat(getFri()));
            case 6:
                setWorkHours(Float.parseFloat(getStat()));
                break;
            default:
                break;
        }
//        if (getWorkDate() == null)
//        {
//            throw new BaseException(400, "当前添加的工时与日期不符");
//        }
    }
}
